<template>
  <div class="bg-white rounded-lg p-5 h-full">
    <div class="font-bold text-lg mb-4">医疗废弃物处置管理</div>

    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="医疗机构名称"
          clearable
          @keyup.enter.native="search"
        />
      </el-form-item>
      <el-form-item  prop="town">
        <el-select
          v-model="queryParams.town"
          filterable
          remote
          clearable
          reserve-keyword
          placeholder="输入街道名称搜索"
          :remote-method="remoteMethod"
        >
          <el-option
            v-for="item in streetOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div class="mb-4">
      <el-button type="primary" @click="search">搜索</el-button>
      <el-button @click="reset">重置</el-button>
    </div>

    <el-table v-loading="loading" border :data="dataList">
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column
        label="医疗机构名称"
        align="center"
        prop="enterpriseName"
      />
      <el-table-column label="所在镇/街道" align="center" prop="town" />
      <el-table-column label="医疗机构所在地址" align="center" prop="addr" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150px"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="toRecordPage(scope.row)"
            >查看处置记录</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import { getHospitalListAPI } from "@/api/zhangping/health-care/base-info";
import { getZpStreetListApi } from "@/api/common";
export default {
  dicts: [
    "waste_manage_status",
    "enterprise_info_type",
    "health_certificate_status",
    "business_file_status",
    "enterprise_category",
  ],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 一企一档表格数据
      dataList: [],
      streetOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseName: null,

        town: null,
      },
    };
  },
  created() {
    this.getDataList();
    this.remoteMethod();
  },
  methods: {
    remoteMethod(query) {
      // const town = this.queryParams.town;
      // console.log(town);

      const params = {
        mname: query,
      };
      console.log(params);

      getZpStreetListApi(params).then((response) => {
        if (response.code === 200) {
          this.streetOptions = response.data.map((item) => {
            return {
              value: item.mname,
              label: item.mname,
            };
          });
        }
      });
    },
    toRecordPage(row) {
      const obj = {
        path: "/health-care/waste-disposal-record",
       
      };
      this.$store.commit("SET_HOSPITAL", row);
      this.$router.push(obj);
    },

    /** 查询一企一档列表 */
    getDataList() {
      this.loading = true;
      getHospitalListAPI(this.queryParams)
        .then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.$refs["queryForm"].resetFields();

      this.search();
    },
    /** 搜索按钮操作 */
    search() {
      this.queryParams.pageNum = 1;
      this.getDataList();
    },
  },
};
</script>
